package com.gosophia.commons;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 生成编号的工具类
 * 
 * @author guodongpo
 * 
 */
public class ReportDateUtil {

    /**
     * 生成数据上报的下一个mission的编号
     * 
     * @param missionCode
     *            数据库中最后的mission编号，可以传入空值
     * @return
     */
    public static String getNextMissionCode(String missionCode) {
        String nextMissionCode = null;
        SimpleDateFormat dateformat = new SimpleDateFormat("yyMMdd");
        String date = dateformat.format(new Date());
        if (missionCode == null || missionCode == "") {
            nextMissionCode = "sjsb" + date + "001";
        } else {
            int code = Integer.parseInt(missionCode.substring(10)) + 1;
            String nextCode = null;
            if (code / 10 == 0) {
                nextCode = "00" + code;
            } else if (code / 100 == 0) {
                nextCode = "0" + code;
            } else {
                nextCode = "" + code;
            }
            nextMissionCode = "sjsb" + date + nextCode;
        }
        return nextMissionCode;
    }
}
